SWEP.Base = "weapon_ic_baseweapon"

if SERVER then
	AddCSLuaFile ("shared.lua")
end

SWEP.Spawnable				= true
SWEP.AdminSpawnable			= true

SWEP.Spawnable				= true
SWEP.AdminSpawnable			= true

SWEP.PrintName			= "ROCKET LAUNCHER"
SWEP.Description		= "Simple single-load weapon that fires armour-piercing rockets. Must be fired whilst crouched and still to be accurate, and quite inefficient against multiple small targets due to the small explosion radius of the rocket."

SWEP.Slot					= 4
SWEP.Cost					= 500
SWEP.PurchasePerAmmo		= true
SWEP.IconFont				= "HL2MPTypeDeath"
SWEP.IconLetter				= "3"

SWEP.Primary.ClipSize		= 1
SWEP.Primary.DefaultClip	= 0
SWEP.Primary.Automatic		= true
SWEP.Primary.Ammo			= "rpg_round"

SWEP.Primary.Sound			= Sound ("Weapon_RPG.Single")

SWEP.Primary.Delay			= 1
SWEP.Primary.Damage			= 450
SWEP.Primary.Cone			= 0.01
SWEP.Primary.Kick			= 8.5
--additional
SWEP.Primary.Radius			= 200
SWEP.Primary.Deviation 		= 0.03

SWEP.Secondary.ClipSize		= -1
SWEP.Secondary.DefaultClip	= -1
SWEP.Secondary.Automatic	= false 
SWEP.Secondary.Ammo			= "none"

SWEP.FiresBullets			= false

SWEP.ViewModel = "models/weapons/v_rpg.mdl"
SWEP.ViewModelFlip = false
SWEP.ViewModelDefPos = Vector (0, 0, 0)
SWEP.ViewModelDefAng = Vector (0, 0, 0)

SWEP.WorldModel = "models/weapons/w_rocket_launcher.mdl"
SWEP.HoldType = "rpg"

if CLIENT then killicon.AddFont("weapon_ic_missilelauncher", SWEP.IconFont, SWEP.IconLetter, Color(255, 80, 0, 255)) end

function SWEP:FireShot ()
	if CLIENT then return end
	
	--accuracy modifiers
	local accmod = 1
	if not self.Owner:Crouching() then
		accmod = accmod * 4
	end
	accmod = accmod + self.Owner:GetVelocity():Length() * 0.01
	
	local rocket = ents.Create ("inc_rpgmissile")
	if rocket and rocket:IsValid() then
		rocket:SetOwner (self.Owner)
		local pos = self.Owner:GetShootPos() + self.Owner:GetAimVector() * 12
		pos = pos + (self.Owner:GetForward() * 5) + (self.Owner:GetRight() * 9) + (self.Owner:GetUp() * -1)
		rocket:SetPos (pos)
		local ang = self.Owner:EyeAngles() + Angle ((math.random() - 0.5) * self.Primary.Cone * accmod * 180,(math.random() - 0.5) * self.Primary.Cone * accmod * 180,(math.random() - 0.5) * self.Primary.Cone * accmod * 180)
		printd ("rocket launching at ang:", ang)
		rocket:SetAngles (ang)
		rocket:Spawn ()
		local mergetable = {
			Inflictor = self.Weapon,
			Attacker = self.Owner,
			Radius = self.Primary.Radius,
			Damage = self.Primary.Damage,
			Deviation = self.Primary.Deviation * accmod
		}
		table.Merge (rocket:GetTable(), mergetable)
		--initial launch pre-flame
		local vecVelocity = rocket:GetForward() * 250
		rocket:GetPhysicsObject():ApplyForceCenter (vecVelocity)
	end
end
